/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities.users;
import entities.tools.FilledForm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Marek
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name="formsigner")
@DiscriminatorValue("FormSigner")
public class FormSigner extends AbstractUser implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 
     */
    @OneToMany(cascade=(CascadeType.PERSIST),fetch = FetchType.LAZY, mappedBy = "formSigner")
    private List<FilledForm> filledForms;

    /**
     * 
     */
    @ManyToMany
    @JoinTable(
            name = "company_form_signer",
            joinColumns = {
                @JoinColumn(name = "form_signer_id", referencedColumnName = "id")},
            inverseJoinColumns = {
                @JoinColumn(name = "company_id", referencedColumnName = "id")})
    private List<CompanyOwner> companyOwners= new ArrayList<>();

    /**
     * 
     */
    @ManyToMany
    @JoinTable(
            name = "form_owner_form_signer",
            joinColumns = {
                @JoinColumn(name = "form_signer_id", referencedColumnName = "id")},
            inverseJoinColumns = {
                @JoinColumn(name = "form_owner_id", referencedColumnName = "id")})
    private List<FormOwner> formOwners = new ArrayList<>();

    /**
     * 
     * @return id  
     */
    @Override
    public Long getId() {
        return id;
    }

    /**
     * 
     * @param id 
     */
    @Override
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 
     * @return hash
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**
     * Check if the instances of FormSigner are equals
     * @param object
     * @return 
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FormSigner)) {
            return false;
        }
        FormSigner other = (FormSigner) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @return the string representation of the FormSigner object 
     */
    @Override
    public String toString() {
        return "entities.users.FormSigner[ id=" + id + " ]";
    }

    


    /**
     * @return the filledForms
     */
    public List<FilledForm> getFilledForms() {
        return filledForms;
    }

    /**
     * @param filledForms the filledForms to set
     */
    public void setFilledForms(List<FilledForm> filledForms) {
        this.filledForms = filledForms;
    }

    /**
     * @return formOwners the formOwners
     */
    public List<FormOwner> getFormOwners() {
        return formOwners;
    }

    /**
     * @param formOwners the formOwners to set
     */
    public void setFormOwners(List<FormOwner> formOwners) {
        this.formOwners = formOwners;
    }

    /**
     * @return the companyOwners
     */
    public List<CompanyOwner> getCompanyOwners() {
        return companyOwners;
    }

    /**
     * @param companyOwners the companyOwners to set
     */
    public void setCompanyOwners(List<CompanyOwner> companyOwners) {
        this.companyOwners = companyOwners;
    }

}
